# 窗口一些参数的设置页面
import tkinter as tk
from tkinter import colorchooser
import config

def settings():
    """
    用于设置窗口的一些参数，如窗口大小、标题、背景颜色等。
    """
    def change_background_color():
        """
        用于更改窗口的背景颜色。
        """
        # 使用颜色选择器选择颜色
        color = colorchooser.askcolor()[1]
        if color:
            # 更新窗口背景颜色
            config.background_color = color
            now_background_color.config(text=color)
    def change_reference_color():
        color = colorchooser.askcolor()[1]
        if color:
            config.reference_color = color
            now_reference_color.config(text=color)
    def cancel_reference():
        config.reference_color = config.background_color
        now_reference_color.config(text="无")
    window = tk.Tk()
    # 设置窗口大小和标题
    window.resizable(False,False)
    # 获取屏幕的宽度和高度
    screen_width = window.winfo_screenwidth()
    screen_height = window.winfo_screenheight()
    width = 380
    height = 540
    # 计算窗口左上角的坐标
    x = (screen_width - width) // 2
    y = (screen_height - height) // 2
    window.title("设置")
    # 设置窗口大小和位置
    window.geometry(f"{width}x{height}+{x}+{y}")
    # 设置更改背景颜色
    frame_background = tk.Frame(window)
    frame_background.pack()
    # 创建frame框架的三个标签和按钮
    label_background_color = tk.Label(frame_background,text="背景颜色:",width=10,height=1,font=("Arial",10))
    label_background_color.grid(row=0,column=0,pady=8)
    now_background_color = tk.Label(frame_background,text=config.background_color,width=10,height=1,font=("Arial",10))
    now_background_color.grid(row=0,column=1,pady=8)
    # 创建更改背景颜色的按钮
    button_background_color = tk.Button(frame_background,text="更改",width=5,height=1,command=change_background_color,font=("Arial",10))
    button_background_color.grid(row=0,column=2,padx=10)
    # 设置更改参考系颜色
    frame_reference = tk.Frame(window)
    frame_reference.pack()
    # 创建frame框架的三个标签和按钮
    label_reference_color = tk.Label(frame_reference,text="参考系颜色:",width=10,height=1,font=("Arial",10))
    label_reference_color.grid(row=0,column=0,pady=8)
    now_reference_color = tk.Label(frame_reference,text=config.reference_color,width=10,height=1,font=("Arial",10))
    now_reference_color.grid(row=0,column=1,pady=8)
    # 创建更改参考系颜色的按钮
    button_reference_color = tk.Button(frame_reference,text="更改",width=5,height=1,command=change_reference_color,font=("Arial",10))
    button_reference_color.grid(row=0,column=2,padx=10)
    # 创建取消参考系的按钮
    button_cancel_reference = tk.Button(frame_reference,text="取消",width=5,height=1,command=cancel_reference,font=("Arial",10))
    button_cancel_reference.grid(row=0,column=3)
    frame_object = tk.Frame(window)
    frame_object.pack()
    # 创建frame框架的三个标签和按钮
    label_object_color = tk.Label(frame_object,text="物体颜色:",width=10,height=1,font=("Arial",10))
    label_object_color.grid(row=0,column=0,pady=8)
    now_object_color = tk.Label(frame_object,text=config.object_color,width=10,height=1,font=("Arial",10))
    now_object_color.grid(row=0,column=1,pady=8)
    # 创建更改物体颜色的按钮
    def change_object_color():
        color = colorchooser.askcolor()[1]
        if color:
            config.object_color = color
            now_object_color.config(text=color)
    button_object_color = tk.Button(frame_object,text="更改",width=5,height=1,command=change_object_color,font=("Arial",10))
    button_object_color.grid(row=0,column=2,padx=10)
    label_warn = tk.Label(window,text="关闭窗口才能立即应用更改后的设置！",width=30,height=1,font=("Arial",10))
    label_warn.pack(pady=5)
    window.mainloop()
